/*
package com.duowan.realtime.scheduled.batch.reader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.backoff.FixedBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

*/
/**
 * @author tangsicheng
 * @version 1.0
 * @since 1.0
 * 利用SPRING 提供的retry模块来重试step,默认的重试机制{@link SimpleRetryPolicy}
 * 重试间隔是{@link FixedBackOffPolicy}，默认重试3次，间隔10秒。重试的总时长不要超过
 * 作业的间隔时间。
 *//*

public class RedisKVRetryReader extends RedisKVReader {

    private static final Logger logger = LoggerFactory.getLogger(RedisKVRetryReader.class);

    private static final int DEFAULT_RETRY_TIMES = 3;
    private static final int DEFAULT_RETRY_INTERVAL_MM = 10 * 1000;

    private Map resultRedisKVMap = null;

    private RetryTemplate retryTemplate;

    private Map<Class<? extends Throwable>, Boolean> exceptions;
    private int retryTimes = DEFAULT_RETRY_TIMES;
    private int retryIntervalMM = DEFAULT_RETRY_INTERVAL_MM;


    @Override
    public void open(ExecutionContext executionContext) throws ItemStreamException {

        retryTemplate.execute(new RetryCallback<Void, ItemStreamException>() {
            @Override
            public Void doWithRetry(RetryContext retryContext) throws ItemStreamException {
                int retryCount = retryContext.getRetryCount();
                Throwable throwable = retryContext.getLastThrowable();
                if (retryCount >= 1) {
                    logger.info("retry RedisKVRetryReader " + retryCount + " times, caused by " + throwable.toString());
                }
                resultRedisKVMap = new HashMap();
                evaluedRedisKeys = evalueKeys(redisKeys);
                for (String evaluedRedisKey : evaluedRedisKeys) {
                    Set<String> keys = realTimeRedisDao.getKeysByRegx(evaluedRedisKey);
                    for (String key : keys) {
                        String value = realTimeRedisDao.get(key);
                        logger.info("key: " + key + " value: " + value);
                        resultRedisKVMap.put(key, value);
                    }
                }
                return null;
            }
        });
    }

    private RetryTemplate createDefaultRetryTemplate() {
        RetryTemplate template = new RetryTemplate();
        SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(retryTimes, exceptions);
        template.setRetryPolicy(retryPolicy);
        FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
        backOffPolicy.setBackOffPeriod(retryIntervalMM);
        template.setBackOffPolicy(backOffPolicy);
        return template;
    }


    @Override
    public void update(ExecutionContext executionContext) throws ItemStreamException {
    }

    @Override
    public void close() throws ItemStreamException {

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notEmpty(redisKeys, "请指定要查找的redis key");
        Assert.notEmpty(exceptions, "指定要引发重试的Exception");
        if (retryTemplate == null) {
            retryTemplate = createDefaultRetryTemplate();
        }
    }

    public void setExceptions(Map<Class<? extends Throwable>, Boolean> exceptions) {
        this.exceptions = exceptions;
    }

    public void setRetryTimes(int retryTimes) {
        this.retryTimes = retryTimes;
    }

    public void setRetryIntervalMM(int retryIntervalMM) {
        this.retryIntervalMM = retryIntervalMM;
    }
}
*/
